package com.hanrui.android.fragment.message.audit.contract;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.ContractDetailBean;
import com.hanrui.android.net.contract.message.audit.contract.ContractDetailContract;
import com.hanrui.android.net.presenter.message.audit.contract.ContractDetailPresenter;

import butterknife.BindView;

/**
 * 合同基本信息
 *
 */

public class ContractDetailFragment extends BaseFragment<ContractDetailPresenter> implements ContractDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.duty_people)
    TextView dutyPeople;
    @BindView(R.id.copies_num)
    TextView copiesNum;
    @BindView(R.id.vote_meet)
    TextView voteMeet;
    @BindView(R.id.money_meet)
    TextView moneyMeet;
    @BindView(R.id.wind_meet)
    TextView windMeet;
    @BindView(R.id.submit_time)
    TextView submitTime;
    @BindView(R.id.enclosure_ll1)
    LinearLayout enclosureLl1;
    @BindView(R.id.enclosure1)
    ImageView enclosure1;
    @BindView(R.id.enclosure_ll2)
    LinearLayout enclosureLl2;
    @BindView(R.id.enclosure2)
    ImageView enclosure2;
    @BindView(R.id.enclosure_ll3)
    LinearLayout enclosureLl3;
    @BindView(R.id.enclosure3)
    ImageView enclosure3;
    @BindView(R.id.enclosure_ll4)
    LinearLayout enclosureLl4;
    @BindView(R.id.enclosure4)
    ImageView enclosure4;
    @BindView(R.id.enclosure_ll5)
    LinearLayout enclosureLl5;
    @BindView(R.id.enclosure5)
    ImageView enclosure5;
    @BindView(R.id.build_name)
    TextView buildName;
    @BindView(R.id.build_time)
    TextView buildTime;
    @BindView(R.id.build_phone)
    TextView buildPhone;
    @BindView(R.id.agent_name)
    TextView agentName;
    @BindView(R.id.agent_user)
    TextView agentUser;
    @BindView(R.id.agent_time)
    TextView agentTime;
    @BindView(R.id.agent_phone)
    TextView agentPhone;
    @BindView(R.id.bid_name)
    TextView bidName;
    @BindView(R.id.bid_user)
    TextView bidUser;
    @BindView(R.id.bid_phone)
    TextView bidPhone;
    @BindView(R.id.bid_time)
    TextView bidTime;
    @BindView(R.id.bid_buildname)
    TextView bidBuildname;
    @BindView(R.id.bid_buildphone)
    TextView bidBuildphone;
    @BindView(R.id.bid_price)
    TextView bidPrice;
    @BindView(R.id.bid_money)
    TextView bidMoney;
    @BindView(R.id.bianbiao_title)
    TextView bianbiaoLl;
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;
    @BindView(R.id.co_name)
    TextView coName;
    @BindView(R.id.co_time)
    TextView coTime;
    @BindView(R.id.co_user)
    TextView coUser;
    @BindView(R.id.co_phone)
    TextView coPhone;
    @BindView(R.id.co_meettime)
    TextView coMeettime;
    @BindView(R.id.co_meetuser)
    TextView coMeetuser;
    @BindView(R.id.co_location)
    TextView coLocation;
    @BindView(R.id.co_price)
    TextView coPrice;
    @BindView(R.id.co_money)
    TextView coMoney;
    @BindView(R.id.shenji_title)
    TextView shenjiLl;
    @BindView(R.id.ll_addview2)
    LinearLayout lladdview2;
    @BindView(R.id.invite_num)
    TextView inviteNum;
    @BindView(R.id.invite_starttime)
    TextView inviteStarttime;
    @BindView(R.id.invite_endtime)
    TextView inviteEndtime;
    @BindView(R.id.invite_type)
    TextView inviteType;
    @BindView(R.id.invite_opentime)
    TextView inviteOpentime;
    @BindView(R.id.invite_ask)
    TextView inviteAsk;
    @BindView(R.id.invite_remark)
    TextView inviteRemark;
    @BindView(R.id.enclosure_ll6)
    LinearLayout enclosureLl6;
    @BindView(R.id.enclosure6)
    ImageView enclosure6;
    @BindView(R.id.enclosure_ll7)
    LinearLayout enclosureLl7;
    @BindView(R.id.enclosure7)
    ImageView enclosure7;
    @BindView(R.id.enclosure_ll8)
    LinearLayout enclosureLl8;
    @BindView(R.id.enclosure8)
    ImageView enclosure8;
    @BindView(R.id.receipt_num)
    TextView receiptNum;
    @BindView(R.id.receipt_page)
    TextView receiptPage;
    @BindView(R.id.batch_num)
    TextView batchNum;
    @BindView(R.id.is_akey)
    TextView isAkey;
    @BindView(R.id.measure_area)
    TextView measureArea;
    @BindView(R.id.collection_num)
    TextView collectionNum;
    @BindView(R.id.money_time)
    TextView moneyTime;
    @BindView(R.id.collection_time)
    TextView collectionTime;
    @BindView(R.id.transfer_time)
    TextView transferTime;
    @BindView(R.id.transfer_thing)
    TextView transferThing;
    @BindView(R.id.zhaobiao_name)
    TextView zhaobiaoName;
    @BindView(R.id.zhaobiao_time)
    TextView zhaobiaoTime;
    @BindView(R.id.zhaobiao_user)
    TextView zhaobiaoUser;
    @BindView(R.id.zhaobiao_phone)
    TextView zhaobiaoPhone;
    @BindView(R.id.total)
    TextView total;
    @BindView(R.id.down_money)
    TextView downMoney;
    @BindView(R.id.enclosure_ll9)
    LinearLayout enclosureLl9;
    @BindView(R.id.enclosure9)
    ImageView enclosure9;
    @BindView(R.id.enclosure_ll10)
    LinearLayout enclosureLl10;
    @BindView(R.id.enclosure10)
    ImageView enclosure10;
    @BindView(R.id.collection_house)
    TextView collectionHouse;
    @BindView(R.id.rodline_transfer)
    TextView rodlineTransfer;
    @BindView(R.id.engineering_money)
    TextView engineeringMoney;
    @BindView(R.id.main_build)
    TextView mainBuild;
    @BindView(R.id.starttime)
    TextView starttime;
    @BindView(R.id.endtime)
    TextView endtime;
    @BindView(R.id.design_company)
    TextView designCompany;
    @BindView(R.id.address_user)
    TextView addressUser;
    @BindView(R.id.address_phone)
    TextView addressPhone;
    @BindView(R.id.remarks)
    TextView remarks;
    @BindView(R.id.review_type)
    TextView reviewType;
    @BindView(R.id.subject_entry)
    TextView subjectEntry;
    @BindView(R.id.enclosure_ll11)
    LinearLayout enclosureLl11;
    @BindView(R.id.enclosure11)
    ImageView enclosure11;
    @BindView(R.id.enclosure_ll12)
    LinearLayout enclosureLl12;
    @BindView(R.id.enclosure12)
    ImageView enclosure12;
    @BindView(R.id.subject_main)
    TextView subjectMain;
    @BindView(R.id.enclosure_num1)
    TextView enclosureNum1;
    @BindView(R.id.enclosure_num2)
    TextView enclosureNum2;
    @BindView(R.id.enclosure_num3)
    TextView enclosureNum3;
    @BindView(R.id.enclosure_num4)
    TextView enclosureNum4;
    @BindView(R.id.enclosure_num5)
    TextView enclosureNum5;
    @BindView(R.id.enclosure_num6)
    TextView enclosureNum6;
    @BindView(R.id.enclosure_num7)
    TextView enclosureNum7;
    @BindView(R.id.enclosure_num8)
    TextView enclosureNum8;
    @BindView(R.id.enclosure_num9)
    TextView enclosureNum9;
    @BindView(R.id.enclosure_num10)
    TextView enclosureNum10;
    @BindView(R.id.enclosure_num11)
    TextView enclosureNum11;
    @BindView(R.id.enclosure_num12)
    TextView enclosureNum12;

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_contractdetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.proEleContractBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static ContractDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        ContractDetailFragment fragment = new ContractDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void proEleContractBizDetail(final ContractDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getName()+"合同审批");
            name.setText(data.getDetail().getName());
            thingTitle.setText(data.getDetail().getScale());
            time.setText(data.getDetail().getType());
            pageNum.setText(data.getDetail().getBidMode());
            dutyPeople.setText(data.getDetail().getProType());
            copiesNum.setText(data.getDetail().getSignTime());
            voteMeet.setText(data.getDetail().getEstPrice());
            moneyMeet.setText(data.getDetail().getIsBt());
            windMeet.setText(data.getDetail().getStandType());
            submitTime.setText(data.getDetail().getStandTime());

            if (null != data.getDetail().getFile1() && data.getDetail().getFile1().size() > 0) {

                enclosureLl1.setVisibility(View.VISIBLE);
                enclosureNum1.setText("["+data.getDetail().getFile1().size()+"]");
                enclosure1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile1());

                    }
                });
            }

            if (null != data.getDetail().getFile2() && data.getDetail().getFile2().size() > 0) {

                enclosureLl2.setVisibility(View.VISIBLE);
                enclosureNum2.setText("["+data.getDetail().getFile2().size()+"]");
                enclosure2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile2());

                    }
                });
            }


            if (null != data.getDetail().getFile3() && data.getDetail().getFile3().size() > 0) {

                enclosureLl3.setVisibility(View.VISIBLE);
                enclosureNum3.setText("["+data.getDetail().getFile3().size()+"]");
                enclosure3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile3());

                    }
                });
            }

            if (null != data.getDetail().getFile4() && data.getDetail().getFile4().size() > 0) {

                enclosureLl4.setVisibility(View.VISIBLE);
                enclosureNum4.setText("["+data.getDetail().getFile4().size()+"]");
                enclosure4.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile4());

                    }
                });
            }

            if (null != data.getDetail().getFile5() && data.getDetail().getFile5().size() > 0) {

                enclosureLl5.setVisibility(View.VISIBLE);
                enclosureNum5.setText("["+data.getDetail().getFile5().size()+"]");
                enclosure5.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile5());

                    }
                });
            }


            buildName.setText(data.getDetail().getBuildCompany());
            buildTime.setText(data.getDetail().getDrawTime());
            buildPhone.setText(data.getDetail().getContactsName());
            agentName.setText(data.getDetail().getTenderId());
            agentUser.setText(data.getDetail().getTenderName());
            agentTime.setText(data.getDetail().getTenderTime());
            agentPhone.setText(data.getDetail().getTenderPhone());
            bidName.setText(data.getDetail().getBidName());
            bidUser.setText(data.getDetail().getBidContractName());
            bidPhone.setText(data.getDetail().getBidContractPhone());
            bidTime.setText(data.getDetail().getBidTime());
            bidBuildname.setText(data.getDetail().getBidImplementName());
            bidBuildphone.setText(data.getDetail().getBidImplementPhone());
            bidPrice.setText(data.getDetail().getBidPrice());
            bidMoney.setText(data.getDetail().getBidCost());

            if (null != data.getDetail().getBidList() && data.getDetail().getBidList().size() > 0) {

                bianbiaoLl.setVisibility(View.VISIBLE);
                lladdview.setVisibility(View.VISIBLE);
                for (int i = 0; i < data.getDetail().getBidList().size(); i++) {

                    addViewItem(data.getDetail().getBidList().get(i));
                }

            }

            coName.setText(data.getDetail().getAuditName());
            coTime.setText(data.getDetail().getAuditProTime());
            coUser.setText(data.getDetail().getAuditContractName());
            coPhone.setText(data.getDetail().getAuditContractPhone());
            coMeettime.setText(data.getDetail().getAuditTime());
            coMeetuser.setText(data.getDetail().getAuditMember());
            coLocation.setText(data.getDetail().getAuditPlace());
            coPrice.setText(data.getDetail().getAuditPrice());
            coMoney.setText(data.getDetail().getAuditCost());

            if (null != data.getDetail().getAuditList() && data.getDetail().getAuditList().size() > 0) {

                shenjiLl.setVisibility(View.VISIBLE);
                lladdview2.setVisibility(View.VISIBLE);
                for (int i = 0; i < data.getDetail().getAuditList().size(); i++) {

                    addViewItem1(data.getDetail().getAuditList().get(i));
                }
            }

            inviteNum.setText(data.getDetail().getTenderNo());
            inviteStarttime.setText(data.getDetail().getTenderStartTime());
            inviteEndtime.setText(data.getDetail().getTenderEndTime());
            inviteType.setText(data.getDetail().getTenderAudType());
            inviteOpentime.setText(data.getDetail().getTenderOpenTime());
            inviteAsk.setText(data.getDetail().getTenderMemberReq());
            inviteRemark.setText(data.getDetail().getTenderMarks());

            if (null != data.getDetail().getFile6() && data.getDetail().getFile6().size() > 0) {

                enclosureLl6.setVisibility(View.VISIBLE);
                enclosureNum6.setText("["+data.getDetail().getFile6().size()+"]");
                enclosure6.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile6());

                    }
                });
            }

            if (null != data.getDetail().getFile7() && data.getDetail().getFile7().size() > 0) {

                enclosureLl7.setVisibility(View.VISIBLE);
                enclosureNum7.setText("["+data.getDetail().getFile7().size()+"]");
                enclosure7.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile7());

                    }
                });
            }

            if (null != data.getDetail().getFile8() && data.getDetail().getFile8().size() > 0) {

                enclosureLl8.setVisibility(View.VISIBLE);
                enclosureNum8.setText("["+data.getDetail().getFile8().size()+"]");
                enclosure8.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile8());

                    }
                });
            }

            receiptNum.setText(data.getDetail().getBusName());
            receiptPage.setText(data.getDetail().getNo());
            batchNum.setText(data.getDetail().getContractEstPrice());
            isAkey.setText(data.getDetail().getContent());
            measureArea.setText(data.getDetail().getSecondName());
            collectionNum.setText(data.getDetail().getWinBidPrice());
            moneyTime.setText(data.getDetail().getEpQuanlit());
            collectionTime.setText(data.getDetail().getLegalRp());
            transferTime.setText(data.getDetail().getLegalPhone());
            transferThing.setText(data.getDetail().getProMgQuanlit());
            zhaobiaoName.setText(data.getDetail().getProMg());
            zhaobiaoTime.setText(data.getDetail().getProMgPhone());
            zhaobiaoUser.setText(data.getDetail().getStartTime());
            zhaobiaoPhone.setText(data.getDetail().getCompletTime());
            total.setText(data.getDetail().getPayCondit());
            downMoney.setText(data.getDetail().getBidRemarks());

            if (null != data.getDetail().getFile9() && data.getDetail().getFile9().size() > 0) {

                enclosureLl9.setVisibility(View.VISIBLE);
                enclosureNum9.setText("["+data.getDetail().getFile9().size()+"]");
                enclosure9.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile9());

                    }
                });
            }


            if (null != data.getDetail().getFile10() && data.getDetail().getFile10().size() > 0) {

                enclosureLl10.setVisibility(View.VISIBLE);
                enclosureNum10.setText("["+data.getDetail().getFile10().size()+"]");
                enclosure10.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile10());

                    }
                });
            }

            collectionHouse.setText(data.getDetail().getContractName());
            rodlineTransfer.setText(data.getDetail().getExecutionDate());
            engineeringMoney.setText(data.getDetail().getPriceType());
            mainBuild.setText(data.getDetail().getMainName());
            starttime.setText(data.getDetail().getSecondName());
            endtime.setText(data.getDetail().getCtPrice());
            designCompany.setText(data.getDetail().getThirdName());
            addressUser.setText(data.getDetail().getPayContent());
            addressPhone.setText(data.getDetail().getAdjust());
            remarks.setText(data.getDetail().getAssure());
            reviewType.setText(data.getDetail().getContract());
            subjectEntry.setText(data.getDetail().getOtherContent());


            if (null != data.getDetail().getFile11() && data.getDetail().getFile11().size() > 0) {

                enclosureLl11.setVisibility(View.VISIBLE);
                enclosureNum11.setText("["+data.getDetail().getFile11().size()+"]");
                enclosure11.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile11());

                    }
                });
            }


            if (null != data.getDetail().getFile12() && data.getDetail().getFile12().size() > 0) {

                enclosureLl12.setVisibility(View.VISIBLE);
                enclosureNum12.setText("["+data.getDetail().getFile12().size()+"]");
                enclosure12.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getDetail().getFile12());

                    }
                });
            }

            subjectMain.setText(data.getDetail().getRemarks());

        }

    }


    //添加ViewItem
    private void addViewItem(ContractDetailBean.DetailBean.BidListBean bean) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_bianbiao, null);
        TextView name = hotelEvaluateView.findViewById(R.id.name);
        TextView thingTitle = hotelEvaluateView.findViewById(R.id.thing_title);

        name.setText(bean.getName());
        thingTitle.setText(bean.getPrice());


        lladdview.addView(hotelEvaluateView);
    }


    //添加ViewItem
    private void addViewItem1(ContractDetailBean.DetailBean.AuditListBean bean) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_shenji, null);
        TextView name = hotelEvaluateView.findViewById(R.id.name);
        TextView thingTitle = hotelEvaluateView.findViewById(R.id.thing_title);

        name.setText(bean.getName());
        thingTitle.setText(bean.getPrice());

        lladdview2.addView(hotelEvaluateView);
    }


}
